package com.example.hzzrpc.config;

import com.example.hzzrpc.config.netty.NettyMainServer;
import com.example.hzzrpc.config.registrycenter.RpcServerContext;
import com.example.hzzrpc.config.registrycenter.RpcServerRegistrarBeanPostProcesser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
 * @author ：hzz
 * @description：TODO
 * @date ：2022/1/2 10:58
 */
@EnableConfigurationProperties({RpcProperties.class})
@Import({RpcServerRegistrarBeanPostProcesser.class})
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class RpcAutoConfiguration {
    private  RpcProperties properties;



    @Bean
    public RpcServerContext getRpcServerContext(){
        return  new RpcServerContext();
    }

    @Bean
    public NettyMainServer nettyMainServer(@Autowired RpcServerContext rpcServerContext){
        NettyMainServer nettyMainServer = new NettyMainServer();
        try {
            nettyMainServer.createNettyServer(rpcServerContext);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return nettyMainServer;
    }


}
